package com.shawn.model.vo;

import com.shawn.commons.utils.RC;
import com.shawn.model.entity.UserInfo;
import com.shawn.model.mongo.Movement;
import lombok.Data;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author shawn
 * @date 2022年 12月 21日 14:37
 */
@Data
public class MovementDetailVo {
    private String id;  //动态id
    private String nickname;
    private Integer userId;
    private String userLogo;
    private Date createDate;
    private String text;
    private String[] medias;
    private Integer state;
    private Integer topState;
    private Integer commentCount;//评论数
    private Integer likeCount;//点赞数
    private Integer reportCount;//喜欢数
    private Integer forwardingCount;//喜欢数
    public static MovementDetailVo init(UserInfo userInfo, Movement movement) {
        MovementDetailVo vo = new MovementDetailVo();
        //设置动态数据
        BeanUtils.copyProperties(movement, vo);
        //设置用户数据
        BeanUtils.copyProperties(userInfo, vo);
        vo.setId(movement.getId().toHexString());
        vo.setUserId(Math.toIntExact(userInfo.getId()));
        vo.setText(movement.getTextContent());
        //初始化标签
        //图片列表
        vo.setMedias(movement.getMedias().toArray(new String[]{}));
        //设置动态发布时间
        Date date = new Date(movement.getCreated());
        vo.setCreateDate(date);
        vo.setReportCount(RandomUtils.nextInt(1,10));
        vo.setForwardingCount(RandomUtils.nextInt(1,100));
        return vo;
    }
}
